<?php
// +----------------------------------------------------------------------
// | Desc: [ Better-充值审核 ]
// +----------------------------------------------------------------------
// | Author: huangzhen_20210406
// +----------------------------------------------------------------------

namespace app\common\model;
use app\api\controller\EmailSend;
use think\facade\Db;

class SearchTrans extends Common
{
    //---------------------------------------------后端---------------------------------------------------------------
    /**
     * @param $post
     * @param $type
     * @return array
     */
    public function tableDataAdmin($post)
    {
        $list_rows  = $post['limit'] ?? config('paginate.list_rows');
        $page       = $post['page'] ?? config('paginate.page');

        $where =[];
        if(isset($post['card_type']) && !empty($post['card_type'])){
            $where[] = ['card_type', '=', trim($post['card_type'])];
        }
        if(isset($post['tran_status']) && !empty($post['tran_status'])){
            $where[] = ['st.status', '=', trim($post['tran_status'])];
        }

        if(isset($post['datetime']) && !empty($post['datetime'])){
            $time_list = explode(' _ ' , $post['datetime']);
            $start_time = $time_list[0] . " 00:00:00";
            $end_time   = $time_list[1] . " 23:59:59";
            $where[] = ['time_auth', 'between', "{$start_time},{$end_time}"];
        }

        $list = Db::name('search_trans')->alias('st')
            ->leftJoin('user u' , 'u.id=st.user_id')
            ->field('u.username,st.*')
            ->order('st.time_auth desc')
            ->where($where)
            ->paginate(['list_rows' => $list_rows, 'page' => $page])
            ->toArray();

        return $result = [
            'code'  => 0,
            'msg'   => lang('get info success'),
            'data'  => $list['data'],
            'count' => $list['total'],
        ];
    }
}